import 'package:adb_flutter/adb_flutter.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    AdbFlutter.stream.listen((event) {
      print(event);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: () {
                      AdbFlutter.connect("127.0.0.1", 5555);
                    },
                    child: const Text("connect")),
                Row(
                  children: [
                    Expanded(
                        child: TextField(
                      controller: controller,
                    )),
                    ElevatedButton(
                        onPressed: () {
                          AdbFlutter.execute(controller.text);
                        },
                        child: const Text("execute ls")),
                  ],
                ),
                ElevatedButton(
                    onPressed: () {
                      AdbFlutter.disconnect();
                    },
                    child: const Text("disconnect")),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
